package com.net.xpay.web.controller.merchant;

import com.google.common.base.Preconditions;
import com.net.common.model.ResultData;
import com.net.xpay.common.domain.User;
import com.net.xpay.common.service.ImageService;
import com.net.xpay.web.secutiry.RequestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

/**
  on 20/03/2018.
 * 处理单文件或者多文件上传
 */
@RestController
@RequestMapping("/merchant/image")
@Api(tags = "商户/图片上传", description = "商户 图片上传 net")
public class ImageController {
    @Autowired
    private ImageService imageService;

    @ApiOperation("上传图片")
    @PostMapping
    public ResultData<String> saveImage(@ApiIgnore @RequestUser User user, @RequestParam(value = "file", required = false) MultipartFile file) {
        Preconditions.checkArgument(file != null);

        String url = imageService.saveImage(user, file);
        return new ResultData<>(url);
    }

}
